package com.youku.wangheng.utils;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mortbay.util.ajax.JSONObjectConvertor;

public class HttpUtil {

	public static void main(String[] args) throws JSONException {
		
		doPost();
	}
	
	private static void doPost() throws JSONException {
		String url = "http://localhost:8080/store/kvstore/put";
		
		Map<String, String> params = new HashMap<String, String>();
		params.put("appid", "wangheng");
		JSONArray array = new JSONArray();
		JSONObject jsonObject =null;
		
		jsonObject = new JSONObject();
		jsonObject.put("key", "test01");
		jsonObject.put("value", "value0001");
		array.put(jsonObject);
		
		jsonObject = new JSONObject();
		jsonObject.put("key", "test02");
		jsonObject.put("value", "value0002");
		array.put(jsonObject);
		
		jsonObject = new JSONObject();
		jsonObject.put("key", "test03");
		jsonObject.put("value", "value0003");
		array.put(jsonObject);
		
		params.put("storeData", array.toString());
		
		
		String result = Request.requestPost(url, params);
		System.out.println(result);
	}
	
	private static void doGet() {
		String url = "";
		
		String result = Request.requestGet(url);
		System.out.println(result);
	}
}
